//
//  WBStatusCellTopView.swift
//  微博
//
//  Created by lipengfei on 15/9/8.
//  Copyright © 2015年 lipengfei. All rights reserved.
//

import UIKit
import SDWebImage

class WBStatusCellTopView: UIView {
///  视图模型
    var statusViewModel: WBStatusViewModel?{
        didSet{
            //sd_setImageWithUrl函数是oc的，参数可以传递为nil
            iconView.sd_setImageWithURL(statusViewModel?.userIconUrl)
            nameLabel.text = statusViewModel?.name
            memberView.image = statusViewModel?.userMemberImage
            vipView.image = statusViewModel?.userVipImage
        }
    }
    ///重写构造函数
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
 /// 向TopView中添加控件
    private func setupUI(){
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(memberView)
        addSubview(vipView)
        
        //自动布局
        let offset = CGPoint(x: 10, y: 0)
        //iconView
        iconView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: 40, height: 40),offset:CGPoint(x: 10, y: 10))
        //nameLabel
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: offset)
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: offset)
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: timeLabel, size: nil, offset: offset)
        memberView.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: nameLabel, size: nil, offset: offset)
        vipView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 8))
    }
    
    
///  TopView 中的属性
    ///懒加载 TopView中的属性
    // 1. iconView
    // 制定默认的头像
    lazy var iconView:UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    // 昵称
    lazy var nameLabel:UILabel = UILabel(title: "姓名", color: UIColor.darkGrayColor(), fontSize: 18)
    // 会员等级
    lazy var memberView:UIImageView = UIImageView (image: UIImage(named: "common_icon_membership_level1"))
    // 发布时间
    lazy var timeLabel:UILabel = UILabel(title: "刚刚", color: UIColor.orangeColor(), fontSize: 12)
    // 来源
    lazy var sourceLabel:UILabel = UILabel(title: "来自 新浪微博", color: UIColor.darkGrayColor(), fontSize: 12)
    // 会员
    lazy var vipView : UIImageView = UIImageView(image: UIImage(named: "avatar_grassroot"))
    
}
